/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_dal
 * FILE       : WordProblemDAO.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Oct 7, 2011  mycodetalks			       Created
 */
package net.lwf.hibernate.dao;

import java.util.List;

import net.lwf.exception.ExceptionUtil;
import net.lwf.hibernate.entity.wp.WpData;
import net.lwf.hibernate.util.HibernateUtil;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

public class WordProblemDAO extends BaseDAO {

	@SuppressWarnings("unchecked")
	public List<WpData> getWordProblems(String grade, String type) {
		List<WpData> data = null;
	    Session session = HibernateUtil.getSessionFactory().openSession();
	    try {
	    	Criteria criteria = session.createCriteria(WpData.class);
	    	criteria.add(Restrictions.eq("grade", grade));
	    	criteria.add(Restrictions.eq("type", type));
	    	data = criteria.list();
	    }
	    catch(HibernateException hex) {
	    	ExceptionUtil.logAndThrowException(WordProblemDAO.class, hex);
	    }
	    finally {
	    	if(session != null) {
	    		session.close();
	    	}
	    }
		return data;
	}
	
} //WordProblemDAO
